package com.jwinni.IO.ReaderAndWriter;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/*
* 字符流
* Reader 字符输出流
* Writer 字符输入流
* */
public class DemoReaderWriter {

    public static void main(String[] args) {
        //WriterFile();
        ReaderFile();
    }

    //读取文件
    //使用文件输入流
    public static  void ReaderFile(){
        FileReader fr = null;
        try {
            fr = new FileReader("static/b.txt");

        char[] chars = new char[1024];

        int len=0;
        while ((len=fr.read(chars))!=-1){
            System.out.println(new String(chars,0,len));

        }
        } catch (IOException e) {
            e.printStackTrace();
        }
        finally {
            if (fr !=null){
                try {
                    fr.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
    }

    //写文件
   //使用文件输出流
    public static  void WriterFile(){
        FileWriter fw =null;
        try {
             fw = new FileWriter("static/b.txt",true);
            //char[] chars = new char[]{'d','我','e'};

            fw.write("我是最帅的");
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }





    }
}
